package com.yanqu.road.dao.impl.config;

import com.yanqu.road.dao.db.DbNameStrategy;
import com.yanqu.road.dao.impl.TempDao;
import com.yanqu.road.entity.config.sacrifice.SacrificeBoss;

import java.math.BigInteger;
import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class SacrificeDaoImpl extends TempDao {

    public Map<Integer, SacrificeBoss> getSacrificeBossMap() {
        ResultSet rs = null;
        CallableStatement call = null;
        String sql = "select * from t_p_sacrifice_boss order by level";
        Map<Integer, SacrificeBoss> dataMap = new ConcurrentHashMap<>();
        try {
            getDb().setConnName(DbNameStrategy.getConfigDb());
            call = getDb().getConnection().prepareCall(sql);
            rs = call.executeQuery();
            while (rs.next()) {
                SacrificeBoss data = new SacrificeBoss();
                data.setLevel(rs.getInt("level"));
                data.setBlood(new BigInteger(rs.getString("hp")));
                dataMap.put(data.getLevel(), data);
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return dataMap;
    }
}
